package com.action;

import lombok.Data;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@Data
public class LoginAction {
    private String account;
    private String password;
    public String execute(){
        HttpServletRequest req = ServletActionContext.getRequest();

        if("root".equalsIgnoreCase(account) && "123".equals(password)){
            HttpSession session = ServletActionContext.getRequest().getSession();
            session.setAttribute("admin",req.getParameter("account"));
            return "success";
        }else{
            if(account==null || "".equals(account)){
                ServletActionContext.getContext().put("msg","账号必须填写");
            }else if(password==null || "".equals(password)){
                ServletActionContext.getContext().put("msg","密码必须填写");
            }else{
                ServletActionContext.getContext().put("msg","账号和密码不正确");
            }
            return "fail";
        }
    }
}
